package com.zjj.learn.designmodel.work.visitor;

/**
 * 计算周长的访问者，提供每一种元素的周长计算方法
 **/
public class PerimeterCalculator implements Visitor {

    private double perimeter;

    public double getPerimeter() {
        return perimeter;
    }

    @Override
    public void visitRectangle(Rectangle rectangle) {
        perimeter = 2 * (rectangle.getWidth() + rectangle.getHeight());
    }

    @Override
    public void visitCircle(Circle circle) {
        perimeter = 2 * Math.PI * circle.getRadius();
    }

    @Override
    public void visitTextBox(TextBox textBox) {
        // do nothing
    }
}
